package com.woniuxy.hrm.config;

import com.woniuxy.hrm.util.RabbitmqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitConfig {
    //检查订单状态消息队列
    @Bean
    public Queue checkOrderStatusQueue(){
        return new Queue(RabbitmqConst.CHECK_ORDER_STATUS_QUEUE);
    }
    //延迟交换机
    public CustomExchange delayExchange(){
        Map map = new HashMap();
        //指定交换机类型
        map.put("x-delayed-type","direct");
        /**
         * 参数1：指定交换机名字
         * 参数2：指定交换机的消息类型（延迟消息）
         * 参数3：是否持久化
         * 参数4：是否自动删除
         * 参数5：其他参数（指定交换机类型）
         */
        return new CustomExchange(RabbitmqConst.DELAY_EXCHANGE,"x-delayed-message",
                true,false,map);
    }
    //绑定交换机与消息队列
    @Bean
    public Binding checkOrderStatusQueueToDelayExchange(){
        return BindingBuilder.bind(checkOrderStatusQueue()).to(delayExchange()).with("delay").noargs();
    }
    @Bean
    public Queue AddOrderQueue(){
        return new Queue(RabbitmqConst.ADD_ORDER_QUEUE);
    }
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(RabbitmqConst.TOPIC_EXCHANGE,true,false);
    }
    @Bean
    public Binding ADDQueueToTopicExchange(){
        return BindingBuilder.bind(AddOrderQueue()).to(topicExchange()).with("add");
    }
    @Bean
    public Queue AddOrderQueue1(){
        return new Queue(RabbitmqConst.ADD_ORDER_QUEUE1);
    }
    @Bean
    public TopicExchange topicExchange1() {
        return new TopicExchange(RabbitmqConst.TOPIC_EXCHANGE1,true,false);
    }
    @Bean
    public Binding ADDQueue1ToTopicExchange1(){
        return BindingBuilder.bind(AddOrderQueue1()).to(topicExchange1()).with("add1");
    }


}
